<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous"/>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
</head>
<body>
<div id="app">
    <div>
        <table style="position: absolute;left: 50px">
            <tr v-for="type in typeList">
                <td v-text="type.name"></td>
                <td>
                    <input type="button" @click.prevent="updateBy(type.id)" value="编辑">
                    <input type="button" @click.prevent="deleteBy(type.id)" value="删除">
                </td>
            </tr>
            <tr>
                <td><a href="/add.html"><input type="button" value="新增"></a> </td>
            </tr>
        </table>
    </div>
</div>
</body>
<script>
    let bookType = new Vue({
        el: "#app",
        data:{
            typeList:[]
        },
        methods: {
            getTypes(){
                let vueObj = this;
                $.post("/bookType/getTypes",function (data) {
                    console.log(data);
                    vueObj.typeList = data;
                })
            },
            updateBy(typeId){
                console.log(typeId);
                sessionStorage.setItem("typeId",typeId)
                location.href="/update.html"
            },
            deleteBy(typeId){
                console.log(typeId);
                let vueObj = this;
                $.post("/bookType/delete",{typeId:typeId},function () {
                    vueObj.getTypes();
                })
            }
        },
        created() {
            this.getTypes()
        }
    })
</script>
</html>